package org.creavi.engine.model;

import com.jmex.model.animation.KeyframeController;

public class AdvancedKeyframeController extends KeyframeController {
	private static final long serialVersionUID = 1L;
	
	private float notifyTime;
	
	private KeyframeListener keyframeListener;
	
	public AdvancedKeyframeController() {
		super();
	}

	public float getNotifyTime() {
		return notifyTime;
	}

	public void setNotifyTime(float notifyTime) {
		this.notifyTime = notifyTime;
	}

	public KeyframeListener getKeyframeListener() {
		return keyframeListener;
	}

	public void setKeyframeListener(KeyframeListener keyframeListener) {
		this.keyframeListener = keyframeListener;
	}

	public void update(float time) {
		boolean callNotifyer = time + getCurTime() >= notifyTime && getCurTime() < notifyTime;
		if (keyframeListener != null && callNotifyer) {
			keyframeListener.beforeApply(this, getCurTime(), time);
			super.update(time);
			keyframeListener.afterApply(this, getCurTime());
		} else {
			super.update(time);
		}
	}
}
